<?php
namespace phpString;
function study(){
	echo "PHP字符串\n";
	echo '统计字符串长度、查询某个子字符串在字符串的位置、去除字符串前后的特殊字符(\t、\n等)、将字符串打散为数组、将数组拼接成数组、在字符串中插入字符、将字符串的首字母、单词的首字母、字符串大小写转换、md5/sha1、将字符串解析到变量或数组中、替换';
	$str = '   Hello world   ';
	$arr = ['1','2','3'];
	echo 'str:'.$str."\n";
	echo 'strlen:'.strlen($str)."\n";
	echo 'strpos:'.strpos($str, 'world')."\t".'stripos:'.stripos($str,'WORLD')."\n";
	echo 'ltrim:'.ltrim($str).'ltrim word:'.ltrim($str,' Helo').'rtrim:'.rtrim($str).'trim:'.trim($str)."\n";
	$str = trim($str);
	printf("%u"."\n",crc32($str));
	var_dump(explode(' ', $str));
	echo 'implode:'.implode($arr)."\n";
	echo 'implode:'.implode('.',$arr)."\n";
	echo 'chunk_split:'.chunk_split($str,1,'.')."\n";
	echo 'str_split:'."\n";
	print_r(str_split($str,2));
	$file = fopen('test.txt','w');
	fprintf($file,'fprintf:'.$str."\n");
	echo "lcfirst:".lcfirst('Hello world')."\tucfirst:".ucfirst('hello world')."\tucwords:".ucwords('hello world')."\tstrtoupper:".strtoupper('hello world')."\tstrtolower:".strtolower('HELLO WORLD')."\n";
	echo levenshtein('Hello World','ell World')."\n";
	echo 'md5:'.md5('test.txt')."\t".'md5_file:'.md5_file('test.txt')."\n";
	echo 'sha1:'.sha1('test.txt')."\t".'sha1_file:'.sha1_file('test.txt')."\n";
	parse_str('name=LSD&age=5');
	parse_str('car=BWM&worth=5k',$arr);
	echo 'parse_str:name='.$name.'age='.$age."\n";
	print_r($arr);
	$str = 'age:39 weight:60kg';
	sscanf($str,'age:%d weight:%dkg',$age,$weight);
	echo 'sscanf:'.$age.$weight."\n";
	echo 'str_ireplace:'.str_ireplace('worLd','Peter','hello WoRlD')."\t".'str_replace:'.str_replace('World','Peter','Hello World')."\n";
	echo 'str_pad:'.str_pad($str,30,'-',STR_PAD_BOTH)."\n";	
	echo 'str_repeat:'.str_repeat($str,5)."\n";
	echo 'str_word_count:'.str_word_count($str)."\n";	
	echo 'str_shuffle:'.str_shuffle($str)."\n";
}

?>
